package net.itgoo.parkingpay.ui.signin;

import net.itgoo.parkingpay.R;
import net.itgoo.parkingpay.manage.ParkingManage;

import java.util.Map;

/**
 * Created by apple on 16/11/21.
 */
public class ParkingSigninPresenter implements ParkingSigninContract.Presenter {

    private final ParkingSigninContract.View mView;
    private final ParkingSigninContract.DataSource mRepository;
    private Map<String, String> mParams;

    public ParkingSigninPresenter(Map<String, String> params, ParkingSigninContract.View view,
                                  ParkingSigninContract.DataSource repository) {
        mView = view;
        mRepository = repository;
        mParams = params;
        view.setPresenter(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {
        mRepository.cancel();
    }

    @Override
    public void signIn(String username, String password) {
        if (username.isEmpty()) {
            mView.showSignInFailure(mView.getContext().getString(R.string.parking_please_input_username));
            return;
        }

        if (password.isEmpty()) {
            mView.showSignInFailure(mView.getContext().getString(R.string.parking_please_input_password));
            return;
        }

        mView.showSignInSuccess();

        ParkingManage.getInstance(mView.getContext())
                .setUser(username, "1234567890");
    }
}
